package com.fnzn.entranceGuard.util;

import com.fnzn.entranceGuard.constant.GuardConstant;

/**
 * @author wf_sxf@163.com
 * @date 2018-08-17 10:43
 */
public enum StatusEnum {
    FAIL(GuardConstant.QR_FAIL,0,"开门失败，无权限。"), SUCCESS(GuardConstant.QR_SUCCESS,1,"开门成功。"), INVALID(GuardConstant.QR_INVALID,2,"开门失败，二维码已过期。");

     StatusEnum(String name, Integer code,String des) {
        this.code = code;
        this.name = name;
        this.des = des;
    }
    private Integer code;

    private String name;

    private String des;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    /**
     * 根据code的值获取name。
     *
     * @param code 活动状态的值
     * @return 枚举对象
     */
    public static String getStatusByCode(Integer code) {
        StatusEnum[] allStatus = StatusEnum.values();
        for (StatusEnum ws : allStatus) {
            if (ws.getCode().equals(code)) {
                return ws.getName();
            }
        }
        return "500";
       // throw new IllegalArgumentException("code非法，没有符合关系类型的枚举对象");
    }
    /**
     * 根据code的值获取des。
     *
     * @param code 活动状态的值
     * @return 枚举对象
     */
    public static String getDesByCode(Integer code) {
        StatusEnum[] allStatus = StatusEnum.values();
        for (StatusEnum ws : allStatus) {
            if (ws.getCode().equals(code)) {
                return ws.getDes();
            }
        }
        return "code值非法，没有符合关系类型的枚举对象";
        //throw new IllegalArgumentException("code非法，没有符合关系类型的枚举对象");
    }
}
